package com.zoffy.ybuhelper.dao;

import androidx.room.*;
import com.zoffy.ybuhelper.pojo.entity.Menu;

import java.util.List;

@Dao
public interface MenuDao {
    @Query("SELECT id,name,origin_id,deleted FROM menu")
    List<Menu> getAll();
    @Query("SELECT id,name,origin_id,deleted FROM menu WHERE deleted=0 and (SELECT deleted FROM origin WHERE id=origin_id)=0")
    List<Menu> getUndeletedAll();
    @Insert
    long insert(Menu menu);
    @Query("Delete From menu where id=:id;")
    void delete(Integer id);
    @Query("SELECT id,name,origin_id,deleted FROM menu WHERE id=:id")
    Menu queryById(Integer id);
    @Query("UPDATE menu SET name=:name WHERE id=:id")
    void updateName(Integer id, String name);
    @Query("UPDATE menu SET origin_id=:originId WHERE id=:id")
    void updateOriginId(Integer id,Integer originId);
    @Query("UPDATE menu SET deleted=:deleted WHERE id=:id")
    void updateDeleted(Integer id,Integer deleted);
    @Query("SELECT id,name,origin_id,deleted FROM menu WHERE origin_id=:id and deleted=0 and ((SELECT deleted from origin where origin_id=:id)=0)")
    List<Menu> getAllByOriginId(Integer id);
    @Query("SELECT id,name,origin_id,deleted FROM menu WHERE (deleted=0 and id in(SELECT menu_id FROM menu_category WHERE category_id=:id))")
    List<Menu> getAllByCategoryId(Integer id);
}
